<?php //debug($idVenta);exit;       ?>
<div class="row">
    <div class="col-md-8">
        <?php if(empty($ultimoPedido)): ?>
        <h3 class="page-title">
            Pedido 
        </h3>
        <?php else: ?>
        <h3 class="page-title">
            Pedido Cliente: <b><?php echo $ultimoPedido['Cliente']['nombre']; ?></b>
        </h3>    
        <?php endif; ?>
        <!-- BEGIN SAMPLE TABLE PORTLET-->
        <div class="portlet box green">
            <div class="portlet-title">
                <div class="caption"><i class="icon-cogs"></i>Lista de Items</div>
                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                </div>
            </div>
            <div class="portlet-body">
                <div class="table-responsive" id="contenidoventas">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>No.</th>
                                <th>Producto</th>
                                <th>Categoria</th>
                                <th>Cantidad</th>                                                                
                                <th>Acciones</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php //echo $this->Form->create('Movimiento');?>
                            <?php $i=1; ?>
                            <?php foreach ($itemsPedido as $ip): ?>                            
                                <tr>                                    
                                    <td><?php echo $i; ?></td>
                                    <td><?php echo $ip['Producto']['nombre']; ?></td>
                                    <td><?php echo $ip['Item']['cantidad']; ?></td>
                                    <td><?php echo $ip['Item']['medida']; ?></td>                                                                        
                                    <td></td>                                    
                                    <?php $i++; ?>                               
                                </tr>
                            <?php endforeach; ?>   
                        </tbody>
                    </table>
                    
                    <div style="text-align: right;">
                        <h3>Total: <?php echo $total; ?></h3>
                    </div>
                </div>

            </div>
        </div>
        <!-- END SAMPLE TABLE PORTLET-->
    </div>
    <div class="col-md-4">
        <h3 class="page-title">
            Seleccione Item 
        </h3>
        <div class="portlet box green">
            <div class="portlet-title">
                <div class="caption">
                    <i class="icon-reorder"></i> Datos de Venta
                </div>
                <div class="tools">
                    <a href="" class="collapse"></a>

                </div>
            </div>
            <div class="portlet-body form">
                <div role="form">
                    <?php echo $this->Form->create('Pedido'); ?>
                    <div class="form-body">
                        <?php if(empty($ultimoPedido)): ?>
                        <div class="form-group">
                            <label>Cliente</label>
                            <?php echo $this->Form->select('cliente_id', $clientes, array('class' => 'form-control input-large select2me', 'data-placeholder' => 'Seleccione el cliente', 'required')); ?>                          
                        </div>
                        <?php else: ?>
                        <?php endif; ?>
                        <?php //echo $this->Form->create('Movimiento'); ?>
                        <div class="form-group">
                            <label >Productos</label>
                            <?php echo $this->Form->select('producto_id', $productos, array('class' => 'form-control input-large select2me', 'data-placeholder' => 'Seleccione el Producto', 'required', 'id' => 'selectproducto')); ?>                           
                            <script>
                                $('#selectproducto').change(function(){
                                    var id = $('#selectproducto').val();
                                    //alert('Cambio'+id);
                                    $('#divdetalleproducto').load('<?php echo $this->Html->url(array('controller'=>'Movimientos', 'action'=>'detalleproducto')); ?>/'+id);
                                });
                            </script>
                        </div>
                        <div class="form-group" id="divdetalleproducto">
                        </div>
                        <div class="portlet-body">
                            <ul  class="nav nav-tabs">
                                <li class="active"><a href="#tab_1_1" data-toggle="tab">Cajas</a></li>
                                <li class=""><a href="#tab_1_2" data-toggle="tab">Unidades</a></li>
                            </ul>
                            <div  class="tab-content">
                                <div class="tab-pane fade active in" id="tab_1_1">
                                    <div class="form-group">
                                        <label >Cantidad de cajas</label>
                                        <?php echo $this->Form->text('cajas', array('class' => 'form-control input-small', 'type' => 'number', 'min' => 1, 'id' => 'cantidadpro')); ?>
                                        <?php echo $this->Form->hidden('venta_id', array('value' => $idVenta)); ?>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="tab_1_2">
                                    <div class="form-group">
                                        <label >Cantidad de Medias  Cajas</label>
                                        <?php echo $this->Form->text('media_caja', array('class' => 'form-control input-small', 'type' => 'number', 'min' => 1, 'id' => 'cantidadpro')); ?>                                        
                                    </div>
                                </div>                              
                            </div>
                        </div>
                        <button type="submit" class="btn green"><i class="icon-arrow-left"></i> Adicionar Pedido</button>
                        <?php $this->Form->end(); ?>                        
                        <br />
                        <div class="form-group">
                            <label>Total Cancelado</label>                            
                        </div>
                    </div>                    
                </div>
                <div class="form-actions right">
                    <?php //echo $this->Html->link('Terminar Venta',array('action' => 'notaventa',$idVenta),array('class' => 'btn blue'));  ?> 
                    <button type="button" class="btn default" onclick="location = '<?php echo $this->Html->url(array('action' => 'cancelaventa', $idVenta)); ?>'">Cancelar</button>  
                    <button type="submit" class="btn blue" >Terminar Venta</button>                             
                </div>
            </div>
        </div>
    </div>

</div>
<div class="modal fade" id="basic" tabindex="-1" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">Editar Almacen</h4>
            </div>
            <?php echo $this->Form->create('Movimiento', array('action' => 'nuevo')); ?>
            <div class="modal-body" id="editar">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn default" data-dismiss="modal">Close</button>
                <button type="submit" class="btn blue">Guardar</button>
            </div>
            <?php echo $this->Form->end(); ?>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<?php echo $this->Js->writeBuffer(); ?>